#!/bin/sh
# autorun.sh - program to run when user inserts cd
#
# copyright (c) 2001 Joseph Cheek, Lycoris
# joseph@lycoris.com, www.lycoris.com
# released under GPL

BUILD_NUM=62

CDROM_BASE=`dirname $0`
TEMP=/tmp
cd $CDROM_BASE

GREETING="Welcome to Desktop/LX!"
WHICH_CD=
CD_NAME=
SOFTWARE=extra/RPMS

# source cd?
if [ -d rl/install/SRPMS ]; then
  WHICH_CD=SOURCE
  CD_NAME=Source
  GREETING="Desktop/LX Source CD"
  SOFTWARE=install/SRPMS
fi

# devtools cd?
if [ -d rl/devel/RPMS ]; then
  WHICH_CD=DEVTOOLS
  CD_NAME=DevTools
  GREETING="Desktop/LX DevTools CD"
  SOFTWARE=devel/RPMS
fi


PLAYCMD=play
[ `ps x | grep [a]rtsd | wc -l` -gt 0 ] && PLAYCMD=artsplay
#artsd running?  use artsplay instead

$PLAYCMD rl/autorun/Start.wav

# copy html to TEMP so it can be modified
cd rl/autorun

TEMPDIR=$TEMP/lycoris.cd.$$
mkdir $TEMPDIR

# index.html main.html navbar.html whats_new.html
cp index.html main.html navbar.html whats_new.html $TEMPDIR

# software.html
cp software_head.html $TEMPDIR/software.html

# make them writeable
chmod +w $TEMPDIR/*

cd ../$SOFTWARE
for a in *rpm; do
  NAME=`rpmextr --tag=name $a`
  SUMMARY=`rpmextr --tag=summary $a`
  DESC=`rpmextr --tag=description $a`
  TEXT='<tr><td valign=top><a href=@@CDROM_BASE@@/rl/'$SOFTWARE'/'$a'><img
    src=@@CDROM_BASE@@/rl/autorun/install_software48_white.png border=0
    width=48 height=48></a></td>
    <td><a href=@@CDROM_BASE@@/rl/'$SOFTWARE'/'$a'><font
    size=+2><strong>'$NAME\ \($SUMMARY\)'</strong></font></a><br>
    '$DESC'
    </td>
    </tr>'
  echo $TEXT >> $TEMPDIR/software.html
done
cd -

cat software_tail.html >> $TEMPDIR/software.html
perl -pi -e s,'\@\@CDROM_BASE\@\@',$CDROM_BASE,g $TEMPDIR/*.html
perl -pi -e s,'\@\@GREETING\@\@',"$GREETING",g $TEMPDIR/*.html
perl -pi -e s,'\@\@CD_NAME\@\@',"$CD_NAME",g $TEMPDIR/*.html

# do they have the dialog profile?
if [ -r /opt/kde2/share/apps/konqueror/profiles/dialog ]; then
  kfmclient openProfile dialog $TEMPDIR/index.html
else
# no, use std konq.
  kfmclient openURL file:$TEMPDIR/index.html
fi

# devtools cd?
if [ "$WHICH_CD" = "DEVTOOLS" ]; then
  [ -x install_devtools.sh ] && BUILD_NUM=$BUILD_NUM ./install_devtools.sh
fi

# cleanup
# rm -rf $TEMPDIR
